/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package UI;

import javax.swing.JFrame;

import CLIENT.Station.mainStation;
import OperateurSystem.GestionAuthentificationPackage.ClientExistantException;
import OperateurSystem.GestionAuthentificationPackage.ClientInexistantException;

/**
 * 
 * @author macmed
 */
public class StationUI extends javax.swing.JFrame {

	/**
	 * Creates new form Station
	 */
	public StationUI() {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jPanel2 = new javax.swing.JPanel();
		jLabel2 = new javax.swing.JLabel();
		butOkAuthTRANSPORTEUR = new javax.swing.JButton();
		jLabel5 = new javax.swing.JLabel();
		textNoFRS = new javax.swing.JTextField();
		jPanel3 = new javax.swing.JPanel();
		jLabel3 = new javax.swing.JLabel();
		butOkNouvelADHERENT = new javax.swing.JButton();
		checkBoxTransporteur = new javax.swing.JCheckBox();
		texAdresPost = new javax.swing.JTextField();
		jLabel7 = new javax.swing.JLabel();
		jLabel8 = new javax.swing.JLabel();
		texNomOuRaiSoc = new javax.swing.JTextField();
		jLabel9 = new javax.swing.JLabel();
		texCordoBancaires = new javax.swing.JTextField();
		jPanel4 = new javax.swing.JPanel();
		jLabel4 = new javax.swing.JLabel();
		butOkAuthADHERENT = new javax.swing.JButton();
		jLabel1 = new javax.swing.JLabel();
		textNoAdh = new javax.swing.JTextField();
		jScrollPane1 = new javax.swing.JScrollPane();
		texConsole = new javax.swing.JTextArea();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		jPanel2.setBackground(new java.awt.Color(204, 204, 255));

		jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
		jLabel2.setText("Authentification des transporteurs");

		butOkAuthTRANSPORTEUR.setText("Ok");
		butOkAuthTRANSPORTEUR
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						butOkAuthTRANSPORTEURActionPerformed(evt);
					}
				});

		jLabel5.setText("No Frs :");

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
				jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout
				.setHorizontalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addGroup(
												jPanel2Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																javax.swing.GroupLayout.Alignment.TRAILING,
																jPanel2Layout
																		.createSequentialGroup()
																		.addContainerGap(
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE)
																		.addComponent(
																				butOkAuthTRANSPORTEUR))
														.addGroup(
																jPanel2Layout
																		.createSequentialGroup()
																		.addComponent(
																				jLabel2)
																		.addGap(0,
																				0,
																				Short.MAX_VALUE))
														.addGroup(
																javax.swing.GroupLayout.Alignment.TRAILING,
																jPanel2Layout
																		.createSequentialGroup()
																		.addGap(0,
																				0,
																				Short.MAX_VALUE)
																		.addComponent(
																				jLabel5)
																		.addGap(88,
																				88,
																				88)
																		.addComponent(
																				textNoFRS,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				122,
																				javax.swing.GroupLayout.PREFERRED_SIZE)))
										.addContainerGap()));
		jPanel2Layout
				.setVerticalGroup(jPanel2Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel2Layout
										.createSequentialGroup()
										.addComponent(jLabel2)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addGroup(
												jPanel2Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel5)
														.addComponent(
																textNoFRS,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(butOkAuthTRANSPORTEUR)
										.addGap(46, 46, 46)));

		jPanel3.setBackground(new java.awt.Color(204, 204, 204));

		jLabel3.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
		jLabel3.setText("Nouvel Adherent");

		butOkNouvelADHERENT.setText("Ok");
		butOkNouvelADHERENT
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						 
							try {
								butOkNouvelADHERENTActionPerformed(evt);
							} catch (NumberFormatException e) {
								texConsole.setText("Un numéro de compte bancaire doit être numérique");
					    		
							} catch (ClientExistantException e) {
									
								texConsole.setText("Ce numéro de compte est deja existant");
							}
						
					}
				});

		checkBoxTransporteur.setText("Je suis un transporteur");

		jLabel7.setText("Nom ou Raison sociale :");

		jLabel8.setText("Adresse postale :");

		jLabel9.setText("Coordonnees Bancaires :");

		javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(
				jPanel3);
		jPanel3.setLayout(jPanel3Layout);
		jPanel3Layout
				.setHorizontalGroup(jPanel3Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel3Layout
										.createSequentialGroup()
										.addGroup(
												jPanel3Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																jPanel3Layout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				jLabel3))
														.addGroup(
																jPanel3Layout
																		.createSequentialGroup()
																		.addGap(59,
																				59,
																				59)
																		.addGroup(
																				jPanel3Layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								butOkNouvelADHERENT)
																						.addGroup(
																								jPanel3Layout
																										.createSequentialGroup()
																										.addGroup(
																												jPanel3Layout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING)
																														.addGroup(
																																jPanel3Layout
																																		.createParallelGroup(
																																				javax.swing.GroupLayout.Alignment.TRAILING,
																																				false)
																																		.addComponent(
																																				jLabel7,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				Short.MAX_VALUE)
																																		.addComponent(
																																				jLabel8,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				Short.MAX_VALUE))
																														.addComponent(
																																jLabel9))
																										.addGap(18,
																												18,
																												18)
																										.addGroup(
																												jPanel3Layout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING,
																																false)
																														.addComponent(
																																texAdresPost)
																														.addComponent(
																																texNomOuRaiSoc)
																														.addComponent(
																																texCordoBancaires,
																																javax.swing.GroupLayout.Alignment.TRAILING,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																294,
																																Short.MAX_VALUE)))))
														.addGroup(
																jPanel3Layout
																		.createSequentialGroup()
																		.addGap(50,
																				50,
																				50)
																		.addComponent(
																				checkBoxTransporteur)))
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));
		jPanel3Layout
				.setVerticalGroup(jPanel3Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel3Layout
										.createSequentialGroup()
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addComponent(jLabel3)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addComponent(checkBoxTransporteur)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addGroup(
												jPanel3Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel7)
														.addComponent(
																texNomOuRaiSoc,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel3Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel8)
														.addComponent(
																texAdresPost,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel3Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel9)
														.addComponent(
																texCordoBancaires,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(27, 27, 27)
										.addComponent(butOkNouvelADHERENT)));

		jPanel4.setBackground(new java.awt.Color(51, 204, 255));

		jLabel4.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
		jLabel4.setText("Authentification des adherents");

		butOkAuthADHERENT.setText("Ok");
		butOkAuthADHERENT
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						butOkAuthADHERENTActionPerformed(evt);
					}
				});

		jLabel1.setText("No Adherent :");

		javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(
				jPanel4);
		jPanel4.setLayout(jPanel4Layout);
		jPanel4Layout
				.setHorizontalGroup(jPanel4Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel4Layout
										.createSequentialGroup()
										.addGroup(
												jPanel4Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																jPanel4Layout
																		.createSequentialGroup()
																		.addContainerGap(
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE)
																		.addComponent(
																				butOkAuthADHERENT))
														.addGroup(
																jPanel4Layout
																		.createSequentialGroup()
																		.addGap(37,
																				37,
																				37)
																		.addComponent(
																				jLabel1)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				Short.MAX_VALUE)
																		.addComponent(
																				textNoAdh,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				124,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGroup(
																jPanel4Layout
																		.createSequentialGroup()
																		.addComponent(
																				jLabel4)
																		.addGap(0,
																				0,
																				Short.MAX_VALUE)))
										.addContainerGap()));
		jPanel4Layout
				.setVerticalGroup(jPanel4Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel4Layout
										.createSequentialGroup()
										.addComponent(jLabel4)
										.addGap(18, 18, 18)
										.addGroup(
												jPanel4Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel1)
														.addComponent(
																textNoAdh,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)
										.addComponent(butOkAuthADHERENT)
										.addGap(29, 29, 29)));

		jScrollPane1.setFocusable(false);

		texConsole.setEditable(false);
		texConsole.setColumns(20);
		texConsole.setRows(5);
		texConsole.setText("Console");
		jScrollPane1.setViewportView(texConsole);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap(
										javax.swing.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING,
												false)
												.addComponent(
														jPanel2,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														jPanel4,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE))
								.addGap(18, 18, 18)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING,
												false)
												.addComponent(
														jPanel3,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(jScrollPane1))
								.addContainerGap()));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(32, 32, 32)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING,
												false)
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jPanel4,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		113,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addComponent(
																		jPanel2,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		0,
																		Short.MAX_VALUE))
												.addComponent(
														jPanel3,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(jScrollPane1,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										277,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addContainerGap(
										javax.swing.GroupLayout.DEFAULT_SIZE,
										Short.MAX_VALUE)));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void butOkAuthADHERENTActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_butOkAuthADHERENTActionPerformed
		
		try {
			mainStation.maGestAuth.verifIdentifiantsA(Integer
					.parseInt(textNoAdh.getText()));
			this.setVisible(false);
			JFrame accueilAdh = new accueilAdherentUi();
			accueilAdh.setVisible(true);

		} catch (ClientInexistantException e) {
			texConsole.setText("Compte inexistant");
			this.repaint();

		} catch (NumberFormatException n) {

			texConsole.setText("Un numéro de compte doit être numérique");
			this.repaint();

		}
	}// GEN-LAST:event_butOkAuthADHERENTActionPerformed

	private void butOkAuthTRANSPORTEURActionPerformed(
			java.awt.event.ActionEvent evt) {// GEN-FIRST:event_butOkAuthTRANSPORTEURActionPerformed
		
		try {
			mainStation.maGestAuth.verifIdentifiantsF(Integer
					.parseInt(textNoFRS.getText()));
			this.setVisible(false);
			JFrame accueilFrs = new AccueilFrsUI();
			accueilFrs.setVisible(true);
			this.repaint();
		} catch (ClientInexistantException e) {
			texConsole.setText("Compte inexistant");
			this.repaint();

		} catch (NumberFormatException n) {

			texConsole.setText("Un numéro de compte doit être numérique");
			this.repaint();

		}
	}// GEN-LAST:event_butOkAuthTRANSPORTEURActionPerformed

	private void butOkNouvelADHERENTActionPerformed(
			java.awt.event.ActionEvent evt) throws NumberFormatException,
			ClientExistantException {// GEN-FIRST:event_butOkNouvelADHERENTActionPerformed
		if (CLIENT.Station.mainStation.maGestAuth != null) {
			
			if (checkBoxTransporteur.isSelected()) {
				int retour = CLIENT.Station.mainStation.maGestAuth.adhesionF(
						texNomOuRaiSoc.getText(), texAdresPost.getText(),
						(Integer.parseInt(texCordoBancaires.getText())));
				texConsole.setText("Votre compte Fournisseur a ete crée et votre numéro est :  "+ retour);
				this.repaint();

			} else {
				int retour = CLIENT.Station.mainStation.maGestAuth.adhesionA(
						texNomOuRaiSoc.getText(),
						(Integer.parseInt(texCordoBancaires.getText())),
						mainStation.getMoiMeme().getIdStation(),
						texAdresPost.getText());
				texConsole.setText("Votre compte Adherent a ete crée et votre numéro est :  "+ retour);

				this.repaint();
			}

		}
	}// GEN-LAST:event_butOkNouvelADHERENTActionPerformed

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		/* Set the Nimbus look and feel */
		// <editor-fold defaultstate="collapsed"
		// desc=" Look and feel setting code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase
		 * /tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager
					.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(StationUI.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(StationUI.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(StationUI.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(StationUI.class.getName()).log(
					java.util.logging.Level.SEVERE, null, ex);
		}
		// </editor-fold>

		/* Create and display the form */
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new StationUI().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton butOkAuthADHERENT;
	private javax.swing.JButton butOkAuthTRANSPORTEUR;
	private javax.swing.JButton butOkNouvelADHERENT;
	private javax.swing.JCheckBox checkBoxTransporteur;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel7;
	private javax.swing.JLabel jLabel8;
	private javax.swing.JLabel jLabel9;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JPanel jPanel3;
	private javax.swing.JPanel jPanel4;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTextField texAdresPost;
	public javax.swing.JTextArea texConsole;
	private javax.swing.JTextField texCordoBancaires;
	private javax.swing.JTextField texNomOuRaiSoc;
	private javax.swing.JTextField textNoAdh;
	private javax.swing.JTextField textNoFRS;
	// End of variables declaration//GEN-END:variables
}
